package com.training.permission.action.chengshu;

import com.opensymphony.xwork2.ActionSupport;
import com.training.permission.service.impl.chengshu.PermissionServiceImpl;
import com.training.pojo.chengshu.URole;

@SuppressWarnings("serial")
public class NewRoleAction extends ActionSupport{
	private PermissionServiceImpl permissionService;
	private URole role;
	
	public URole getRole() {
		return role;
	}

	public void setRole(URole role) {
		this.role = role;
	}

	public void setPermissionService(PermissionServiceImpl permissionService) {
		this.permissionService = permissionService;
	}
	
	public String execute(){
		if(!validateInf()){
			return INPUT;
		}else{
			if(permissionService.newRole(role)){
				this.addFieldError("roleResult","新建成功！");
				return SUCCESS;
			}else{
				this.addFieldError("roleResult","新建失败！");
				return INPUT;
			}
		}
	}
	public boolean validateInf(){
		if(role==null){
			return false;
		}else if(role.getRolename().equals("")||role.getRolename()==null){
			this.addFieldError("roleName", "请输入角色名！");
			return false;
		}else if(role.getContent()==null||role.getContent().equals("")){
			this.addFieldError("roleContent", "请输入角色简介！");
			return false;
		}else{
			return true;
		}
	}
	public String show(){
		return SUCCESS;
	}
}
